﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>复选框的反选</title>
    <script language="javascript">  
        function selectOther(chkObj){
            for(let i = 0;i< chkObj.elements.length;i++){
                if(chkObj.elements[i].type == "checkbox"){
                    if(!chkObj.elements[i].checked){
                        chkObj.elements[i].checked=true;
                    }else{
                        chkObj.elements[i].checked=false;
                    }
                }
            }
        }
    </script>
</head>
<body>
<form name="form1">
    <input type="checkbox" id="checkbox1" name="chk" /> 旅游 <br>
    <input type="checkbox" id="checkbox2" name="chk" /> 体育 <br>
    <input type="checkbox" id="checkbox3" name="chk" /> 音乐 <br>
    <input type="button" id="button1" value="反选" onclick="selectOther(document.form1)" />
</form>
</body>
</html>